#!/usr/bin/env narwhal
var packages = require('gelatin/packages');  // under test

var file = require('file'),
    os = require('os'),
    json = require('json'),
    assert = require('test/assert');

var narcissus = require('narcissus'),
    oil = require('oil');

// findModule should return an array of path/handle objects
exports.testMaybePackage = function() {
  var fs = new oil.FileSystem('/home/andy/git/narwhal2/packages/oil'),
      p = new packages.MaybePackage(fs);
  print('OIL ' + json.stringify(p.findModule('oil', 'node'), null, 2));
}

// findModule should return an array of path/handle objects
exports.testPackageSet = function() {
  var fs = new oil.FileSystem('/home/andy/git/narwhal2/packages/oil'),
      p = new packages.MaybePackage(fs);
  var set = new packages.PackageSet([p]);
  var result = set.findModule('oil', 'node');
  print('OIL in set ' + json.stringify(result, null, 2));

  var emptySet = new packages.PackageSet([]);
  try {
    result = emptySet.findModule('oil', 'node');
  } catch (e) {
    var b = e instanceof packages.ModuleNotFound;
    assert.eq(true, b);
  }
}

exports.testMakePackages= function() {
  var p = packages.makePackages(['/home/andy/git/mynarwhal']);
  print('p ' + p);
  print('args ' + p.findModule('args', undefined, 'junk.js'));
}


if (require.main === module.id) {
  require("test/runner").run(exports);
}
